package com.example.administrator.swredeem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.swredeem.R;
import com.example.administrator.swredeem.appBase.Config;
import com.example.administrator.swredeem.beanClass.JFuserBean;
import com.example.administrator.swredeem.net.HttpXutils;
import com.example.administrator.swredeem.net.MyCallback;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RechargeActivity extends AppCompatActivity {

    @BindView(R.id.jf_huhao)
    TextView jfHuhao;
    @BindView(R.id.jf_name)
    TextView jfName;
    @BindView(R.id.jf_addr)
    TextView jfAddr;
    @BindView(R.id.jf_biaohao)
    TextView jfBiaohao;
    @BindView(R.id.bj_type)
    TextView bjType;
    @BindView(R.id.jf_IC_Kh)
    TextView jfICKh;
    @BindView(R.id.jf_bckczql)
    TextView jfBckczql;
    private String qureyid;

    private JFuserBean jFuserBean;
    private Gson gson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        qureyid = getIntent().getStringExtra("qureyid");
        jFuserBean = new JFuserBean();
        gson = new Gson();

        net();
    }

    public void goTobuygas(View view) {
        Intent intent = new Intent(RechargeActivity.this, TobuygasActivity.class);
        intent.putExtra("userid",jFuserBean.getInfo().get(0).getUserid());
        intent.putExtra("title","充值");
        intent.putExtra("factory",jFuserBean.getInfo().get(0).getFactory());
        startActivity(intent);
    }

    private void net() {
        MyCallback myCallback = new MyCallback() {
            @Override
            public void onSuccess(String result) {
                Log.d("TAG", "onSuccess: " + result);
                jFuserBean = gson.fromJson(result, JFuserBean.class);
                setdata(jFuserBean.getInfo().get(0));
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }
        };
        Map<String, String> map = new HashMap<>();
        map.put("spotno", "1");
        map.put("operno", "1");
        map.put("orgcode", "1");
        map.put("dataorgid", "1");
        map.put("qureyid", qureyid);
        map.put("type", "1");

        HttpXutils.getData(Config.ICUserCZ, map, myCallback);
    }

    private void setdata(JFuserBean.InfoBean jf) {

        jfHuhao.setText("户号:"+jf.getUserid());
        jfName.setText("姓名:"+jf.getUsername());
        jfAddr.setText("地址:"+jf.getAddr());
        jfBiaohao.setText("表号:"+jf.getResid());
        bjType.setText("表具类型:"+jf.getRestype());
        jfICKh.setText("表厂家:"+jf.getFactory());
//        jfBckczql.setText("户号:"+jf.getUserid());

    }

}
